#include <iostream>
using namespace std;
int circularTrackIndex(int dist[], int refill[],int n)
{
    if(n==0) return -1;
    int fuel = 0, start=0;
    for(int i=0; i<n; i++)
    {
        fuel+=refill[i]-dist[i];
        if(fuel<0)
        {
            start = i+1;
            fuel = 0;
        }
    }
    return start;
}
int main()
{
    // dist[i] is distance between pit i and i +1
    int dist[] = { 3, 10, 2, 4, 6, 9};
    // refill[i] is fuel available at pit[i]
    int refill[] = { 3, 4, 6, 3, 7, 11};
    int n = sizeof(refill)/sizeof(refill[0]);
    cout<<circularTrackIndex(dist,refill,n);
    return 0;
}
